// pages/activationCode/index.js
const {
  post
} = getApp();
Page({
  data: {
    dataList: [],
    showLoading: true,
    params: {
      child_sn: '',
      page: 1,
      pageSize: 20
    },
  },
  onLoad: function (e) {
    this.setData({
      'params.child_sn': e.sn
    });
    this.getList();
  },
  // 获取数据
  getList() {
    if (this.data.showLoading) {
      post("/activation-code/list", this.data.params).then(res => {
        if (res.result == 1) {
          const dataList = this.data.dataList.concat(res.data);
          this.setData({
            dataList
          });
          if (res.data.result.length < this.data.params.pageSize) {
            this.setData({
              showLoading: false
            })
          }
        };
      })
    }
  },
  // 上拉加载
  onReachBottom: function () {
    this.setData({
      "params.page": this.data.params.page += 1
    });
    this.getList();
  },
  // 复制
  copy: function (e) {
    wx.setClipboardData({
      data: e.currentTarget.dataset.code,
      success: function (res) {
        wx.getClipboardData({
          success: function (res) {
            wx.showToast({
              title: '复制成功'
            })
          }
        })
      }
    })
  },
})